<script setup lang="ts">
import axios from 'axios'
import axiosRetry from 'axios-retry'

const request = axios.create({
  baseURL: 'http://localhost:3000',
  timeout: 1000
})

axiosRetry(request, {
  retries: 3,
  retryDelay: () => 1000,
  shouldResetTimeout: true,
  retryCondition(error) {
    // return error.code === 'ECONNABORTED' || error.code === 'ERR_NETWORK'
    return ['ECONNABORTED', 'ERR_NETWORK'].includes(error.code!)
  }
})

//
const getData = () => {
  request({
    method: 'get',
    url: '/delay_3s_data'
  })
}
</script>

<template>
  <h1>请求重试</h1>
  <button @click="getData">发送请求</button>
</template>
